module ICarry {

    export class FooterViewModel implements PrismBreak.PbViewModel {

        private _app: ICarryApplication;
        private _view: PrismBreak.View;

        private previousButtonVisible: KnockoutObservable<boolean>;
        private nextButtonVisible: KnockoutObservable<boolean>;

        constructor(app: PrismBreak.PbApp) {

            this._app = <ICarryApplication>app;

            this._app.EventManager.Subscribe(ICarry.ICarryEvent[ICarry.ICarryEvent.NextButtonVisibilityChange], (value: boolean) => {
                this.nextButtonVisible(!!value);
            });

            this._app.EventManager.Subscribe(ICarry.ICarryEvent[ICarry.ICarryEvent.PreviousButtonVisibilityChange], (value: boolean) => {
                this.previousButtonVisible(!!value);
            });

        }

        public Initialize(view: PrismBreak.View) {
            this.nextButtonVisible = ko.observable(true);
            this.previousButtonVisible = ko.observable(true);

            ko.applyBindings(this, view.Node);

            this._view = <PrismBreak.View> view;
        }


        public NextStepClickEvent(): void {

            //reset flags

            this.previousButtonVisible(true);
            this.nextButtonVisible(true);

            this._app.EventManager.Publish(PrismBreak.EventType[PrismBreak.EventType.RequestNextStep], this._app.ICarryContext.GetNextStep());

        }

        public PreviousStepClickEvent(): void {

            //reset flags
            this.previousButtonVisible(true);
            this.nextButtonVisible(true);

            this._app.EventManager.Publish(PrismBreak.EventType[PrismBreak.EventType.RequestPreviousStep], this._app.ICarryContext.GetPreviousStep());

        }
    }

}  